﻿using Newtonsoft.Json.Linq;
using SpaceNeedle.x6473.WindowsPhone.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;

namespace SpaceNeedle.x6473.WindowsPhone.Common
{
    public class Facebook
    {
        public static string AccessToken;

        public async static Task Authorize(bool force = false)
        {
            if (force || string.IsNullOrEmpty(AccessToken))
            {
                WebRequest client = new WebRequest();
                string oauthUrl = string.Format("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={0}&client_secret={1}", "174927756041187", "2767fc974c8f7090015d7378124c511e");
                AccessToken = (await client.DownloadStringAsync(oauthUrl, "GET", null)).Split('=')[1];
            }
        }
        public async static Task<JObject> GetPage(string fanpage)
        {
            //await Authorize();

            WebRequest client = new WebRequest();

            string pageInfo = await client.DownloadStringAsync(string.Format("https://graph.facebook.com/{0}", fanpage));

            return JObject.Parse(pageInfo);
        }
    }
}
